﻿/*查询每个章节结果数量*/
var dropdownApp = angular.module("chapterStatis", ["Common"]);
dropdownApp.directive("chaptStatis", ["RequestTrainService", function (RTS) {
    return {
        scope: {
            chitem: "="
        },
        template: "<span>{{chitem.numSum}}</span>",
        //transclude: true,
        replace: true,
        restrict: 'AE',
        link: function ($scope, elm, attr) {
            //    查询每个章节结果数量
            //    cstype:    章节类型(1.视频 2.文档 3.考试(测试)id 4.题库 5.线下 6.直播)
            $scope.csId = $scope.chitem.CSID;
            // 由于后台3 的时候要取得试卷的id那么必须解析chapterJson json 获得试卷id                        
            if ($scope.chitem.CSTYPE == 3) {    //试卷进行单独处理
                $scope.csId = $scope.chitem.chapterJson[0].paperId;                
            }
            // 发送请求
            RTS.chapterQuantity({ csid: $scope.csId, cstype: $scope.chitem.CSTYPE }).then(function (datashare) {
                if (datashare.errorcode == 0) {
                    $scope.chitem.numSum = datashare.numCount;
                } else {
                    $scope.chitem.numSum = "0";
                }
            });
        }
    };
} ]);